package com.xtianzhuang.www.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xtianzhuang.www.dao.TfSlowSqlMapper;
import com.xtianzhuang.www.dao.TfSqlImproveMapper;
import com.xtianzhuang.www.dao.others.TfUserDailyRecordOtherMapper;
import com.xtianzhuang.www.entity.TfSlowSql;
import com.xtianzhuang.www.entity.TfSqlImprove;
import com.xtianzhuang.www.entity.request.SaveSqlImproveRequest;
import com.xtianzhuang.www.entity.response.DailyRecord;
import com.xtianzhuang.www.service.WorkService;
import com.xtianzhuang.www.service.base.BaseServiceBiz;


@Service("workServiceBiz")
@Transactional(rollbackFor = Exception.class)
public class WorkServiceBiz extends BaseServiceBiz implements WorkService {
	@Autowired
	private TfSlowSqlMapper tfSlowSqlMapper;

	@Autowired
	private TfSqlImproveMapper tfSqlImproveMapper;

	@Autowired
	private TfUserDailyRecordOtherMapper tfUserDailyRecordOtherMapper;

	@Override
	public void insertTfSlowSql(TfSlowSql tfSlowSql) {
		// TODO Auto-generated method stub
		tfSlowSqlMapper.insert(tfSlowSql);
	}

	@Override
	public void saveSqlImprove(SaveSqlImproveRequest request) throws Exception {
		// TODO Auto-generated method stub
		TfSqlImprove tfSqlImprove = new TfSqlImprove();
		tfSqlImprove.setCreateTime(new Date());
		tfSqlImprove.setSqlId(request.getSqlId());
		tfSqlImprove.setSqlDetail(request.getSqlDetail());
		tfSqlImprove.setState("00");
		tfSqlImprove.setRemark(request.getRemark());
		tfSqlImprove.setSqlDetailAfter(request.getSqlDetailAfter());
		tfSqlImprove.setCreateStaffId(subject.getPrincipal().getUserName());
		tfSqlImproveMapper.insertSelective(tfSqlImprove);
	}

	@Override
	public List<DailyRecord> getDailyRecordByMonth() {
		// TODO Auto-generated method stub
		return tfUserDailyRecordOtherMapper.getDailyRecordByMonth(subject.getPrincipal().getUserId());
	}

}